package cn.useless;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

import cn.stuManagement.student.Student;

public class TestUser {

	public static void main(String[] args) {
		// test01();
		// test02();
		// test02();
		// test03();
		// 实例化scanner对象，接收标准输入输出
		Scanner sc = new Scanner(System.in);
		// 存储学生信息的文件
		File file = new File("D:/demo/stuData.txt");
		// 学生信息的集合
		List<Student> list = new ArrayList<>();
		// 读取文件中的链表信息
		//System.out.println("List:" + list);
		list = AllStudent.readFile(file);
		//System.out.println("List:" + list);
		// 检查链表数据（在readFile无返回值时为空）
		// for (User user : list) {
		// System.out.println(user);
		// }
		//检测退出的变量
		String exit = null;
		while(true) {
		UserController.inputUserMessage(list);
		//UserController.stuIDFlag++;
		// 格式化输出信息
		// UserController.outputUserMessage(list);
		//提示可选择退出
		System.out.println("退出请输入y，不退出返回任意键");
		exit = sc.next();
		if(exit.equals("y")||exit.equals("Y")) {
			break;
		}
		}
		AllStudent.writeFile(file, list);
		//ObjectIO.readFile(file);

	}

	private static void test03(List list) {
		// 用List存储user信息
		// List<User> listUsers = new LinkedList<>();
		Scanner sc = new Scanner(System.in);
		// 实例化user对象
		Student user1 = new Student();
		user1.setUserID("100111");
		user1.setUserName("llwe");
		user1.setUserAge(18);

		Student user2 = new Student();
		user2.setUserID("100121");
		user2.setUserName("yuys");
		user2.setUserAge(29);

		list.add(user1);
		list.add(user2);
		boolean exit = false;
		while (!exit) {
			// 调用输入
			UserController.inputUserMessage(list);
			// 格式化输出信息
			UserController.outputUserMessage(list);

			// 判断是否继续输入
			System.out.println("如果退出请输入true,不退出请输入false");
			exit = sc.nextBoolean();
			if (exit == true)
				break;
		}

	}

	private static void test02() {
		// 用List存储user信息
		List<Student> listUsers = new LinkedList<>();
		// 实例化user对象
		Student user1 = new Student();
		user1.setUserID("100111");
		user1.setUserName("llwe");
		user1.setUserAge(18);

		Student user2 = new Student();
		user2.setUserID("100121");
		user2.setUserName("yuys");
		user2.setUserAge(29);

		listUsers.add(user1);
		listUsers.add(user2);
		// 调用输入
		UserController.inputUserMessage(listUsers);
		// 格式化输出信息
		UserController.outputUserMessage(listUsers);

	}

	private static void test01() {

		// 实例化map对象
		Map<String, Student> mapUser = new HashMap<>();
		// 实例化user对象
		Student user1 = new Student();
		user1.setUserID("100111");
		user1.setUserName("llwe");
		user1.setUserAge(18);

		Student user2 = new Student();
		user2.setUserID("100121");
		user2.setUserName("yuys");
		user2.setUserAge(29);

		// 将user对象存入map中
		mapUser.put(user1.getUserID(), user1);
		mapUser.put(user2.getUserID(), user2);

		System.out.println("---------------------------------------------");

		// 用keySet方法输出user信息
		Set<String> userKS = mapUser.keySet();
		for (String str : userKS) {
			System.out.println(mapUser.get(str));
		}

		System.out.println("---------------------------------------------");
		// 用entrySet方法输出user信息
		Set<Map.Entry<String, Student>> userES = mapUser.entrySet();
		for (Map.Entry<String, Student> e : userES) {
			System.out.println(e.getValue());
		}
	}

}
